package Servlets;

import PackDatos.GestionBD;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class srv_listar_un_alumnoMatriculado extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        Connection cn = null;
        Map notaalumno = new HashMap();
        HttpSession session = request.getSession(true);
        try {
            response.setContentType("text/html");
            String codigoA = request.getParameter("codigoA");
            String codigoC = request.getParameter("codigoC");
            // conectamos la BD 
            GestionBD og = new GestionBD();
            cn = og.conectar();
            String query = "select id_curso,a.id_alumno,alu_codigo,alu_nombre,alu_apellido,"
                    + "not_practica1,not_practica2,not_practica3,not_practica4,not_prompractica,"
                    + "not_examparcial,not_examfinal,not_promfinal from alumno a inner join nota n"
                    + " on n.id_alumno=a.id_alumno where alu_estado='1' AND a.id_alumno = '" + codigoA + "' AND id_curso="+codigoC;
            Statement stm = cn.createStatement();
            ResultSet rs = stm.executeQuery(query);
            if (rs.next()) {
                // obtenemos un alumno
                notaalumno.put("id_curso", rs.getInt("id_curso"));
                notaalumno.put("id_alumno", rs.getInt("id_alumno"));
                notaalumno.put("alu_codigo", rs.getString("alu_codigo"));
                notaalumno.put("alu_nombre", rs.getString("alu_nombre"));
                notaalumno.put("alu_apellido", rs.getString("alu_apellido"));
                notaalumno.put("not_practica1", rs.getInt("not_practica1"));
                notaalumno.put("not_practica2", rs.getInt("not_practica2"));
                notaalumno.put("not_practica3", rs.getInt("not_practica3"));
                notaalumno.put("not_practica4", rs.getInt("not_practica4"));
                notaalumno.put("not_examparcial", rs.getInt("not_examparcial"));
                notaalumno.put("not_examfinal", rs.getInt("not_examfinal"));
            }   
            session.setAttribute("notaalumno", notaalumno);
            stm.close();
            cn.close();
        } catch (Exception ex) {
            System.out.println("problemas al editar Alumno");
        }
        // generamos la vista y lo devolvemos al cliente
        RequestDispatcher rd = request.getRequestDispatcher("registrarNotasAlumno.jsp");
        rd.forward(request, response);
    }
}
